#ifndef __MUTEX_H
#define __MUTEX_H
#include "stdtype.h"
#include "atom.h"
#include "dlist.h"

/**
 * the mutex struct definition
 */
typedef struct
{
    mx_dlist_pt suspend;    // the thread list that wait for mutex to be leave
    mx_atom_flag_t flag;    // atom flag
} mx_mutex_t, *mx_mutex_pt;

/* initialize the specified mutex */
void mx_mutex_init (mx_mutex_pt pmutex);
/* enter the mutex */
void mx_mutex_enter (mx_mutex_pt pmutex);
/* try to enter the mutex, the thread will not be blocked when get the lock fall */
mx_bool_t mx_mutex_tryenter (mx_mutex_pt pmutex);
/* leave the mutex */
void mx_mutex_leave (mx_mutex_pt pmutex);

#endif
